package demo4;

interface IFlying {
    void fly();
}
interface ISwimming {
    void swim();
}
interface IRunning {
    void run();
}
abstract class Animal {
    private String name;
    private int age;

    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return this.name;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public int getAge() {
        return this.age;
    }
    public  Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public abstract void eat();
}
//先继承类然后实现接口
class Dog extends Animal implements IRunning,ISwimming {
    public Dog(String name, int age) {
        super(name,age);
    }
    public void eat() {
        System.out.println(this.getName() +":正在吃饭");
    }
    @Override
    public void run() {
        System.out.println(this.getName()+":正在跑步");
    }
    @Override
    public void swim() {
        System.out.println(this.getName()+"正在游泳");
    }
}
class Bird extends Animal implements IFlying {
    public Bird(String name, int age) {
        super(name, age);
    }
    @Override
    public void fly() {
        System.out.println(getName()+"正在飞");
    }
    @Override
    public void eat() {
        System.out.println(getName()+"正在吃虫儿");
    }
}
class Robot implements IRunning {
    @Override
    public void run() {
        System.out.println("机器人跑步");
    }
}
public class Test {
    public static void test1(Animal animal) {
        animal.eat();
    }
    public static void testFly(IFlying iFlying) {
        iFlying.fly();
    }
    public static void testSwim(ISwimming iSwimming) {
        iSwimming.swim();
    }
    public static void testRun(IRunning iRunning) {
        iRunning.run();
    }

    public static void main(String[] args) {
        testFly(new Bird("小鸟",12));
        testRun(new Dog("小狗",11));
        testRun(new Dog("小狗",22));
        testRun(new Robot());
    }
    public static void main1(String[] args) {
        test1(new Dog("小狗",23));
    }
}

interface A {
    void testA();
}
interface B {
    void testB();
}
interface C extends A,B {
    void testC();
}
//在AB接口又拓展C接口的目的是解耦
class D implements C {
    @Override
    public void testA() {

    }
    @Override
    public void testB() {

    }
    @Override
    public void testC() {

    }
}